<?php
/**
 * @description : show message for Request An Prod <third-parties payment for it>
 * @author      : stephen.mo <stephen.mo@achievo.com>
 * @date        : Dec 16,2010
 */
require_once "TVB/OAuth/common.inc.php";
#ini_set("display_errors","on");

//get all parameters.
$lang             = (isset($_REQUEST['lang'])) ? OAuthUtils::chkLang($_REQUEST['lang']) : OAuthConfig::DEFAULT_SUPPORT_LANG;
$telco_name       = (isset($_REQUEST['pg'])) ? $_REQUEST['pg'] : NULL;
$call_back        = (isset($_REQUEST['call_back'])) ? $_REQUEST['call_back'] : NULL;
$tvbauth          = (isset($_REQUEST['tvbauth']) && !empty($_REQUEST['tvbauth'])) ? $_REQUEST['tvbauth'] : NULL;

//setting path.
$base_server_path = OAuthConfig::OAuthDomainUrl($_SERVER);
$ajax_url         = $base_server_path.OAuthConfig::DEFAULT_AJAX_URL;
$jqtouch_url      = $base_server_path.OAuthModelConfig::DEFAULT_MOBILE_TEMPLATE;
$plan_details_url = $base_server_path.OAuthConfig::DEFAULT_SUPPORT_PLAN_DETAILS;
$quick_signin_url = $base_server_path.OAuthConfig::DEFAULT_QUICKLY_LOGIN;
$message_url      = $base_server_path.OAuthConfig::DEFAULT_SHOW_MESSAGE_URL;
$failure_page     = $base_server_path."/$telco_name/".OAuthModelConfig::$telco_payment_fail;
$success_page     = $base_server_path."/$telco_name/".OAuthModelConfig::$telco_payment_succ;
$quick_login_url  = $quick_signin_url.'?pg='.$telco_name.'&redirect_to='.urlencode($call_back);
$error_url        = $base_server_path.OAuthConfig::DEFAULT_SHOW_MESSAGE_URL.'?act=request&flag=failure&pg='.$telco_name.'&lang='.$lang;
$cancel_url       = $base_server_path.OAuthConfig::DEFAULT_CMODEL_URL.'?lang='.$lang.'&call_back='.urlencode($call_back);

//check member has logined?
$rec_tvbauth = (!empty($tvbauth)) ? OAuthUtils::chkTvbAuth($tvbauth) : FALSE;
if (!$rec_tvbauth) {
    $confirm_url = $quick_signin_url.'?lang='.$lang.'&pg='.$telco_name.'&redirect_to='.urlencode($call_back);
}
else {
    $confirm_url = $plan_details_url.'?lang='.$lang.'&pg='.$telco_name.'&call_back='.urlencode($call_back).'&tvbauth='.$tvbauth;
}

//if logined and login_id is not empty then set a crumb string.
$crumb_string = NULL;
$params       = array();
if ($rec_tvbauth) {
    $params['exT']      = time()+OAuthModelConfig::THIRD_PAYMENT_EXPIRE_TIME; //unit is second.
    $params['randN']    = rand();
    $params['clientIp'] = (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && $_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
    $params['loginId']  = OAuthUtils::getLoginIdByTvbAuth($login_id);
    $crumb_str          = OAuthUtils::genCrumbString($params,2);
    $crumb_string       = '&exT='.$params['exT'].'&randN='.$params['randN'].'&crumbS='.$crumb_str;
}

//setting page info.
$request_page_info          = OPI::$request_page_info[$lang][$telco_name];
$payment_buttons            = OPI::$payment_button_info[$lang];

//template setting.
$form                       = array();
$using_real_env             = OAuthModelConfig::USING_TEMPLATE_ON_REAL_ENV; 
$page                       = OAuthModelConfig::M_PAGE_OF_PLAN_REQUEST;
$form['lang']               = $lang;
$form['title']              = $request_page_info['page_title'];
$form['pg']                 = $telco_name;
$form['request_title']      = $request_page_info['request_title'];
$form['request_notes']      = $request_page_info['request_notes'];
$form['button']['request']  = array('value'=>$payment_buttons['confirm_request'],'link'=>$confirm_url.$crumb_string);
$form['button']['cancel']   = array('value'=>$payment_buttons['cancel'],'link'=>$cancel_url);

//include this template for page.
include "..".OAuthModelConfig::DEFAULT_MOBILE_TEMPLATE.OAuthModelConfig::$mobile_teplate_page[$page];

?>

